package com.jstyle.jclifexd.activity;

import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Button;
import android.widget.ImageView;

import com.jstyle.blesdk.Util.SingleDealData;
import com.jstyle.blesdk.cmdenum.SendCmdState;
import com.jstyle.blesdk.constant.DeviceKey;
import com.jstyle.jclifexd.R;
import com.jstyle.jclifexd.adapter.WatchFaceStyleAdapter;

import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class WatchFaceStyleActivity extends BaseActivity implements WatchFaceStyleAdapter.onItemClickListener {

    @BindView(R.id.bt_title)
    Button btTitle;
    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.recyclerView_watchStyle)
    RecyclerView recyclerViewWatchStyle;
    private WatchFaceStyleAdapter watchFaceStyleAdapter;

    //    @BindViews({R.id.button_style1, R.id.button_style0, R.id.button_style3, R.id.button_style2})
//    List<View>viewList;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_watch_face_style);
        ButterKnife.bind(this);
        init();
    }

    private void init() {
        writeData(SingleDealData.getDeviceInfo());
        btTitle.setText(getString(R.string.watch_face_style));
        GridLayoutManager gridLayoutManager=new GridLayoutManager(this,3);

        recyclerViewWatchStyle.setLayoutManager(gridLayoutManager);
         watchFaceStyleAdapter=new WatchFaceStyleAdapter("");
        watchFaceStyleAdapter.setOnContactClickListener(this);
        recyclerViewWatchStyle.setAdapter(watchFaceStyleAdapter);
    }

    @OnClick(R.id.iv_back)
    public void onViewClicked() {
        finish();
    }

    @Override
    public void onItemClick(int position) {
        if(position==15){
            startActivity(WatchStyleCustomActivity.class);
        }else {
            writeData(SingleDealData.setWatchFaceStyle(position));
        }

    }
    @Override
    public void dataCallback(Map<String, String> maps, SendCmdState sendCmdState) {
        super.dataCallback(maps, sendCmdState);
        switch (sendCmdState){
            case GET_DEVICE_INFO:
                String watchFaceStyle=maps.get(DeviceKey.KWatchFaceStyle);
                int style=Integer.valueOf(watchFaceStyle);
                watchFaceStyleAdapter.setSelectedPosition(style);
                break;
        }
    }
//
//    @OnClick({R.id.button_style1, R.id.button_style0, R.id.button_style3, R.id.button_style2})
//    public void onViewClicked(View view) {
//        switch (view.getId()) {
//            case R.id.button_style0:
//                setSelected(view.getId());
//                writeData(SingleDealData.setWatchFaceStyle(1));
//                break;
//            case R.id.button_style1:
//                setSelected(view.getId());
//                writeData(SingleDealData.setWatchFaceStyle(0));
//                break;
//            case R.id.button_style2:
//                setSelected(view.getId());
//                writeData(SingleDealData.setWatchFaceStyle(3));
//                break;
//            case R.id.button_style3:
//                setSelected(view.getId());
//                writeData(SingleDealData.setWatchFaceStyle(4));
//                break;
//        }
//    }
//    private void setSelected(int id){
//        for(View view:viewList){
//            view.setSelected(view.getId()==id);
//        }
//    };
}
